<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Bootstrap
 *
 * @author Animus Inc.
 */

define('DOMROOT',dirname(dirname(dirname(__FILE__))));
define('ORMROOT', DOMROOT.'/AnimusORM');

require_once DOMROOT."/classes/APICore/EventLogger.php";

class AnimusBootstrap {
    private $_bootstrapSettings;
    private $_sessionTimeout;
    private $_adminMenuMap;
    private $_userMenuMap;
    private $_adminMenubarRenderSettings;
    private $_userMenubarRenderSettings;
    
    public function __construct() { 
       //Variable declaration
       $this->_bootstrapSettings = new SimpleXMLElement(file_get_contents(DOMROOT.'/config/application-settings.xml'));
       return;
       
    }
    
    public function readAdminMenubar(){
        $adminMenuArray = array();
	$settingsMap = $this -> _bootstrapSettings;
	$adminMenuMap = $settingsMap -> menubar -> admin;
	foreach($adminMenuMap -> menu as $menuItem){
		$menuItemName = (string)$menuItem['name'];
		$menuItemLink = (string)$menuItem['link'];
		$menuItemHasParent = (bool)$menuItem['hasParent'];
                $menuItemParent = (string) $menuItem['parent'];
			if($menuItemHasParent && !is_null($menuItemParent)) $menuItemParent = $menuItemParent['parent'];
			else{
			/* Uncomment after implementing logger				
				devLog($logLevel, "Defined parent but not found for ".$menuItem." check definition.");
			*/

			}
		$adminMenuArray[$menuItemName]['link']=$menuItemLink;
		$adminMenuArray[$menuItemName]['parent']=$menuItemParent;
	}
	$this->_adminMenuMap = $adminMenuArray;
	$renderAs = $adminMenuMap["renderAs"];
	$container= $adminMenuMap["container"];
	$this->_adminMenubarRenderSettings["renderAs"] = $renderAs;
	$this->_adminMenubarRenderSettings["renderAs"]["container"] = $container;
	return;
    }
    
    public function readUserMenubar(){
	$settingsMap = $this -> _bootstrapSettings;
	$userMenuMap = $settingsMap -> menubar -> user;
	foreach($userMenuMap -> menu as $menuItem){
		$menuItemName = (string)$menuItem['name'];
		$menuItemLink = (string)$menuItem['link'];
		$menuItemHasParent = (bool)$menuItem['hasParent'];
                $menuItemParent = (string)$menuItem['parent'];
			if($menuItemHasParent && !is_null($menuItemParent)){ 
                            $menuItemParent = $menuItemParent['parent'];
                        }
                        else{
			/* Uncomment after implementing logger				
				devLog($logLevel, "Defined parent but not found for ".$menuItem." check definition.");
			*/

			}
		$userMenuArray[$menuItemParent]['link']=$menuItemLink;
                $userMenuArray[$menuItemParent]['parent']=$menuItemParent;
	}
	$this->_userMenuMap = $userMenuArray;
	$renderAs = $userMenuMap["renderAs"];
	$container= $userMenuMap["container"];
	$this->_userMenubarRenderSettings["renderAs"] = $renderAs;
	$this->_userMenubarRenderSettings["renderAs"]["container"] = $container;
	return;

    }
    
    public function setTimeout(){
        $this->_sessionTimeout = (integer)$this->_bootstrapSettings->session->timeout*60;
        return;
    }
    public function getTimeout(){
        return $this -> _sessionTimeout;
    }
    public function getAdminMenuMap(){
        return $this->_adminMenuMap;
    }
    public function getUserMenuMap(){
        return $this->_userMenuMap;
    }
    public function getAdminMenubarRenderSettings(){
        return $this->_adminMenubarRenderSettings;
    }
    public function getUserMenubarRenderSettings(){
        return $this->_userMenubarRenderSettings;
    }
    
}

?>
